package com.onlineauction.entities;

import java.util.logging.Logger;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.onlineauction.helpers.CacheHandler;

public class GenericEntity {
	
	protected static Logger LOGGER = Logger.getLogger(GenericEntity.class
			.getName());

	protected static Key storeEntity(Entity entity) {
		DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
		return ds.put(entity);
	}
	
	protected static Entity getEntity(String kind, String keyName) {
		Key key = KeyFactory.createKey(kind, keyName);
		try {
			Entity entity = DatastoreServiceFactory.getDatastoreService().get(key);
			return entity;
		} catch (EntityNotFoundException e) {
			return null;
		}		
	}
	
	protected static Entity getEntity(String kind, long id) {
		Key key = KeyFactory.createKey(kind, id);
		try {
			Entity entity = DatastoreServiceFactory.getDatastoreService().get(key);
			return entity;
		} catch (EntityNotFoundException e) {
			return null;
		}		
	}

}
